﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>云瑞家庭农场</title>
    <link rel="shortcut icon" href="~/Content/assets/i/miemie_favicon.ico" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="~/Content/layui/css/layui.css">
    <script src="~/Content/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/Scripts/jquery-3.3.1.js"></script>
    <script>
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            //日期
            laydate.render({
                elem: '#date'
            });
            laydate.render({
                elem: '#date1'
            });

            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');

            //自定义验证规则


            $(document).ready(function () {
                $("#reguest").click(function () {

                    var Name = $('#name').val();
                    var Sex = $("#sex option:selected").val();
                    var Contacts = $('#contacts').val();
                    var UserName = $('#username').val();
                    var PassWord = $('#password').val();
                    var PassWord2 = $('#password2').val();
                    form.verify({
                        fullname: function (value) {
                            if (value.length < 1) {
                                return '请输入姓名';
                            }
                        }
                        , username: function (value) {
                            if (value.length < 1) {
                                return '请输入用户名';
                            }
                        }
                        , pass: [/(.+){6,12}$/, '密码必须6到12位']
                        , pass2: function (value) {
                            if (PassWord != PassWord2)
                                return '两次输入的密码不相同！';
                        }
                        , content: function (value) {
                            layedit.sync(editIndex);
                        }
                    });
                    if (Name == "") {
                        return;
                    }
                    else if (Contacts == "") {
                        return;
                    }
                    else if (UserName == "") {
                        return;
                    }
                    else if (PassWord == "" || PassWord2 == "") {
                        return;
                    }
                    else if (PassWord != PassWord2) {
                        return;
                    }

                    $.ajax({
                        url: "/YunRuiFarmAPI/RegisterAPI", //请求的URL
                        cache: true, //不从缓存中取数据
                        data: {
                            "Name": Name,
                            "Sex": Sex,
                            "Contacts": Contacts,
                            "UserName": UserName,
                            "Password": PassWord
                        }, //发送的参数
                        type: 'post', //请求类型
                        dataType: 'json', //返回类型是JSON
                        timeout: 20000, //超时

                    })
                        .done(function (result) {
                            if (result.IsSuccess) {
                                layer.msg(result.Message);
                                setTimeout(function () {
                                    window.location.href = '/YunRuiFarm/Login'
                                }, 3000);
                            } else {
                                layer.msg(result.Message);
                            }
                        });
                });
                $("#login").click(function () {
                    window.location.href = "/YunRuiFarm/Login";
                });

            });

        });

    </script>
    <style>
        body {
            text-align: left;
            background-image: url('../../Content/image/login_regestion_background.png');
            background-repeat: no-repeat;
            background-position: 0% 0%;
            background-size: cover;
            background-color: #22C3AA;
            font-size: 18px;
            overflow-y: hidden; /*禁止滚动条*/
        }

        #divtitle {
            margin: 0 auto;
            margin-top: 5%;
            margin-bottom: 5%;
            background-color: rgba(255,255,255,0.5)
        }

        #divcss1 {
            margin: 0 auto;
            border: 1px solid #c0c0c0;
            width: 50%;
            background-color: rgba(255,255,255,0.5)
        }

        #divcss2 {
            margin-top: 10px;
            margin-bottom: 10px;
        }

        #divcss3 {
            
            margin-left: 10%;
        }
    </style>
</head>
<body>
    <div id="divtitle">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>云瑞家庭农场管理系统注册页面</legend>
    </fieldset>
    </div>
    <div id="divcss1">
        <div id="divcss2">
            <div id="divcss3">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-inline">
                                <input type="tel" name="fullname" lay-verify="fullname" autocomplete="off" class="layui-input" id="name">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">联系方式</label>
                            <div class="layui-input-inline">
                                <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入手机号码" id="contacts">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" >性别</label>
                        <div class="layui-input-inline">
                            <select name="sex" id="sex" style="width:96%">
                                <option value="3" selected="">未选择</option>
                                <option value="2">男</option>
                                <option value="1">女</option>
                            </select>
                        </div>
                    </div>
                    
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" lay-verify="username" placeholder="请输入用户名" autocomplete="off" class="layui-input" id="username">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密 码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password" lay-verify="pass" placeholder="请填写6到12位密码" autocomplete="off" class="layui-input" id="password">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">确认密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password2" lay-verify="pass2" placeholder="请输入确认密码" autocomplete="off" class="layui-input" id="password2">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" type="button" id="reguest">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                <button type="button" class="layui-btn layui-btn-primary" id="login">返回登录</button>
                            </div>
                        </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>